<?php
/**
 * Html form for user login
 *
 * @file
 * @ingroup Templates
 */
/**
 * @defgroup Templates Templates
 */
if (!defined('MEDIAWIKI'))
    die(-1);

/**
 * HTML template for Special:Userlogin form
 * @ingroup Templates
 */
class UserloginTemplate extends QuickTemplate {
    
    private $url;
    
    function construct($serveurUrl){
        $this->url = $serverUrl;
    }

    function execute() {
        if ($this->data['message']) {
            ?>
            <div class="<?php $this->text('messagetype') ?>box">
                <?php if ($this->data['messagetype'] == 'error') { ?>
                    <strong><?php $this->msg('loginerror') ?></strong><br />
                <?php } ?>
                <?php $this->html('message') ?>
            </div>
            <div class="visualClear"></div>
        <?php } ?>

        <div id="loginstart"><?php $this->msgWiki('loginstart'); ?></div>
        <table border='0'>
		<tr><td rowspan='2'><img src='<?php echo $this->url ?>/skins/common/images/ban_connexion.jpg'/></td>
		<td>
		<div id="userloginForm">
            <form name="userlogin" method="post" action="<?php $this->text('action') ?>">
                
                <?php $this->html('header'); /* pre-table point for form plugins... */ ?>
                <?php if ($this->haveData('languages')) { ?><div id="languagelinks"><p><?php $this->html('languages'); ?></p></div><?php } ?>
                <table>
                    <tr>
                        <td></td>
                        <td class="mw-input">
                            <?php
                            echo Html::input('wpName', 
                                empty($this->data['name'])? wfMsg( 'login' ) : $this->data['name'], 
                                'text', array(
                                'class' => 'loginText',
                                'id' => 'wpName1',
                                'tabindex' => '16',
                                'size' => '20',
                                'required'
                                    # Can't do + array( 'autofocus' ) because + for arrays in PHP
                                    # only works right for associative arrays!  Thanks, PHP.
                                    ) + ( $this->data['name'] ? array() : array('autofocus' => '') ));
                            ?>

                        </td>
                    </tr>
					
                    <tr>
                        <td></td>
                        <td class="mw-input">
                            <?php
                            echo Html::input('wpPassword', 
                                empty($this->data['password'])? '12345678' : $this->data['password'], 
                                'password', array(
                                'class' => 'loginPassword',
                                'id' => 'wpPassword1',
                                'tabindex' => '17',
                                'size' => '20'
                                    ) + ( $this->data['name'] ? array('autofocus') : array() ));
                            ?>

                        </td>
                    </tr>
                    <?php
                    if (isset($this->data['usedomain']) && $this->data['usedomain']) {
                        $doms = "";
                        foreach ($this->data['domainnames'] as $dom) {
                            $doms .= "<option>" . htmlspecialchars($dom) . "</option>";
                        }
                        ?>
                        <tr id="mw-user-domain-section">
                            <td></td>
                            <td class="mw-input">
                                <select name="wpDomain" value="<?php $this->text('domain') ?>"
                                        tabindex="18">
                                            <?php echo $doms ?>
                                </select>
                            </td>
                        </tr>
                        <?php
                    }

                    if ($this->haveData('extrafields')) {
                        echo $this->data['extrafields'];
                    }

                    if ($this->data['canremember']) {
                        ?>
                        <tr>
                            <td></td>
                            <td class="mw-input">
                                <?php
                                global $wgCookieExpiration, $wgLang;
                                echo Xml::checkLabel(
                                        wfMsgExt('remembermypassword', 'parsemag', $wgLang->formatNum(ceil($wgCookieExpiration / ( 3600 * 24 )))), 'wpRemember', 'wpRemember', $this->data['remember'], array('tabindex' => '19')
                                )
                                ?>
                            </td>
                        </tr>
                    <?php } ?>
                    <?php if ($this->data['cansecurelogin']) { ?>
                        <tr>
                            <td></td>
                            <td class="mw-input">
                                <?php
                                echo Xml::checkLabel(
                                        wfMsg('securelogin-stick-https'), 'wpStickHTTPS', 'wpStickHTTPS', $this->data['stickHTTPS'], array('tabindex' => '20')
                                );
                                ?>
                            </td>
                        </tr>
                    <?php } ?>
                    <tr>
                        <td></td>
                        <td class="mw-submit">

        <?php
        echo Html::input('wpLoginAttempt', wfMsg('login'), 'submit', array(
            'id' => 'wpLoginAttempt',
            'tabindex' => '21'
        ));
        if ($this->data['useemail'] && $this->data['canreset']) {
            if ($this->data['resetlink'] === true) {
                echo '<br/>';
                echo Linker::link(
                        SpecialPage::getTitleFor('PasswordReset'), wfMessage('userlogin-resetlink')
                );
            } elseif ($this->data['resetlink'] === null) {
			
				echo '<br/>';
                echo Linker::link(
                        SpecialPage::getTitleFor('PasswordReset'), wfMessage('userlogin-resetlink')
                );
                //echo '<br/>';
                //echo Html::input('wpMailmypassword', wfMsg('mailmypassword'), 'submit', array(
                  //  'id' => 'wpMailmypassword',
                  // 'tabindex' => '22'
                //));
            }
        }
        ?>

                            <?php
                          /*  echo Html::input('wpLoginAttempt', wfMsg('login'), 'submit', array(
                                'id' => 'wpLoginAttempt',
                                'tabindex' => '21'
                            ));
                            if ($this->data['useemail'] && $this->data['canreset']) {
                                if ($this->data['resetlink'] === true) {
                                    echo '&#160;';
                                    echo Linker::link(
                                            SpecialPage::getTitleFor('PasswordReset'), wfMessage('userlogin-resetlink')
                                    );
                                } elseif ($this->data['resetlink'] === null) {
                                    echo '&#160;';
                                    echo Html::input('wpMailmypassword', wfMsg('mailmypassword'), 'submit', array(
                                        'id' => 'wpMailmypassword',
                                        'tabindex' => '22'
                                    ));
                                }
                            }*/
                            ?>


                        </td>
                    </tr>
                </table>
                <?php if ($this->haveData('uselang')) { ?><input type="hidden" name="uselang" value="<?php $this->text('uselang'); ?>" /><?php } ?>
                <?php if ($this->haveData('token')) { ?><input type="hidden" name="wpLoginToken" value="<?php $this->text('token'); ?>" /><?php } ?>
            </form>
        </div>
        <div id="loginend"><?php $this->html('loginend'); ?></div>

		</td>
		</tr>
		
		<!-- creation compte -->
		<tr>
		<td>

        <?php
        /*if ($this->data['message']) {
            ?>
            <div class="<?php $this->text('messagetype') ?>box">
                <?php if ($this->data['messagetype'] == 'error') { ?>
                    <strong><?php $this->msg('loginerror') ?></strong><br />
                <?php } ?>
                <?php $this->html('message') ?>
            </div>
            <div class="visualClear"></div>
        <?php } */ ?>


        <div id="signupstart"><?php $this->msgWiki('signupstart'); ?></div>
        <div id="userlogin">

            <form name="userlogin2" id="userlogin2" method="post" action="<?php $this->text('actionSignup') ?>">
                <?php $this->html('header'); /* pre-table point for form plugins... */ ?>
                <?php if ($this->haveData('languages')) { ?><div id="languagelinks"><p><?php $this->html('languages'); ?></p></div><?php } ?>
                <table>
                    <tr>
                        <td></td>
                        <td class="mw-input">
                            <?php
                            echo Html::input('wpName', 
                                empty($this->data['name'])? wfMsg('login') : $this->data['name'], 
                                'text', array(
                                'class' => 'loginText',
                                'id' => 'wpName2',
                                'tabindex' => '1',
                                'size' => '20',
                                'required',
                                'autofocus'
                            ));
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td class="mw-input">
                            <?php
                            echo Html::input('wpPassword',
                                empty($this->data['password'])? '12345678' : $this->data['password'],
                                'password', array(
                                'class' => 'loginPassword',
                                'id' => 'wpPassword2',
                                'tabindex' => '2',
                                'size' => '20'
                                    ) + User::passwordChangeInputAttribs());
                            ?>
                        </td>
                    </tr>
                    <?php
                    if ($this->data['usedomain']) {
                        $doms = "";
                        foreach ($this->data['domainnames'] as $dom) {
                            $doms .= "<option>" . htmlspecialchars($dom) . "</option>";
                        }
                        ?>
                        <tr>
                            <td class="mw-label"><?php $this->msg('yourdomainname') ?></td>
                            <td class="mw-input">
                                <select name="wpDomain" value="<?php $this->text('domain') ?>"
                                        tabindex="3">
                                            <?php echo $doms ?>
                                </select>
                            </td>
                        </tr>
                    <?php } ?>
                    <tr>
                        <td></td>
                        <td class="mw-input">
                            <?php
                            echo Html::input('wpRetype', 
                                empty($this->data['retype'])? '12345678' : $this->data['retype'], 
                                'password', array(
                                'class' => 'loginPassword',
                                'id' => 'wpRetype',
                                'tabindex' => '4',
                                'size' => '20'
                                    ) + User::passwordChangeInputAttribs());
                            ?>
                        </td>
                    </tr>
                    <tr>
                        <?php if ($this->data['useemail']) { ?>
                            <td></td>
                            <td class="mw-input">
                                <?php
                                echo Html::input('wpEmail', 
                                    empty($this->data['email'])? wfMsg('email') : $this->data['email'], 
                                    'email', array(
                                    'class' => 'loginText',
                                    'id' => 'wpEmail',
                                    'tabindex' => '5',
                                    'size' => '20'
                                ));
                                ?>

                            </td>
                        <?php } ?>
                        <?php if ($this->data['userealname']) { ?>
                        </tr>
                        <tr>
                            <td></td>
                            <td class="mw-input">
                                <input type='text' class='loginText' name="wpRealName" id="wpRealName"
                                       tabindex="6"
                                       value="<?php empty($this->data['realname'])? $this->msg('yourname') : $this->text('realname'); ?>" size='20' />
                            </td>
                        <?php } ?>
                        <?php if ($this->data['usereason']) { ?>
                        </tr>
                        <tr>
                            <td class="mw-label"><label for='wpReason'><?php $this->msg('createaccountreason') ?></label></td>
                            <td class="mw-input">
                                <input type='text' class='loginText' name="wpReason" id="wpReason"
                                       tabindex="7"
                                       value="<?php $this->text('reason') ?>" size='20' />
                            </td>
                        <?php } ?>
                    </tr>
                    <?php if ($this->data['canremember']) { ?>
                        <tr>
                            <td></td>
                            <td class="mw-input">
                                <?php
                                global $wgCookieExpiration, $wgLang;
                                echo Xml::checkLabel(
                                        wfMsgExt('remembermypassword', 'parsemag', $wgLang->formatNum(ceil($wgCookieExpiration / ( 3600 * 24 )))), 'wpRemember', 'wpRemember', $this->data['remember'], array('tabindex' => '8')
                                )
                                ?>
                            </td>
                        </tr>
                        <?php
                    }

                    $tabIndex = 9;
                    if (isset($this->data['extraInput']) && is_array($this->data['extraInput'])) {
                        foreach ($this->data['extraInput'] as $inputItem) {
                            ?>
                            <tr>
                                <?php
                                if (!empty($inputItem['msg']) && $inputItem['type'] != 'checkbox') {
                                    ?><td class="mw-label"><label for="<?php echo htmlspecialchars($inputItem['name']); ?>"><?php $this->msgWiki($inputItem['msg']) ?></label><?php
                } else {
                                    ?><td><?php
                }
                                ?></td>
                                <td class="mw-input">
                                    <input type="<?php echo htmlspecialchars($inputItem['type']) ?>" name="<?php echo htmlspecialchars($inputItem['name']); ?>"
                                           tabindex="<?php echo $tabIndex++; ?>"
                                           value="<?php
                    if ($inputItem['type'] != 'checkbox') {
                        echo htmlspecialchars($inputItem['value']);
                    } else {
                        echo '1';
                    }
                                ?>" id="<?php echo htmlspecialchars($inputItem['name']); ?>"
                                           <?php
                                           if ($inputItem['type'] == 'checkbox' && !empty($inputItem['value']))
                                               echo 'checked="checked"';
                                           ?> /> <?php
                           if ($inputItem['type'] == 'checkbox' && !empty($inputItem['msg'])) {
                                               ?>
                                        <label for="<?php echo htmlspecialchars($inputItem['name']); ?>"><?php $this->msgHtml($inputItem['msg']) ?></label><?php
                       }
                       if ($inputItem['helptext'] !== false) {
                                               ?>
                                        <div class="prefsectiontip">
                                            <?php $this->msgWiki($inputItem['helptext']); ?>
                                        </div>
                                    <?php } ?>
                                </td>
                            </tr>
                            <?php
                        }
                    }
                    ?>
                    <tr>
                        <td></td>
                        <td class="mw-submit">
                            <input type='submit' name="wpCreateaccount" id="wpCreateaccount"
                                   tabindex="<?php echo $tabIndex++; ?>"
                                   value="<?php $this->msg('createaccount') ?>" />
                                   <?php if ($this->data['createemail']) { ?>
                                <input type='submit' name="wpCreateaccountMail" id="wpCreateaccountMail"
                                       tabindex="<?php echo $tabIndex++; ?>"
                                       value="<?php $this->msg('createaccountmail') ?>" />
                                   <?php } ?>
                        </td>
                    </tr>
                </table>
                <?php if ($this->haveData('uselang')) { ?><input type="hidden" name="uselang" value="<?php $this->text('uselang'); ?>" /><?php } ?>
                <?php if ($this->haveData('token')) { ?><input type="hidden" name="wpCreateaccountToken" value="<?php $this->text('token'); ?>" /><?php } ?>
            </form>
        </div>
        <div id="signupend"><?php $this->html('signupend'); ?></div>
		</td></tr></table>
        <div id="newsfeed"></div>

                <?php
            
			
			}
			
			

    function addInputItem($name, $value, $type, $msg, $helptext = false) {
        $this->data['extraInput'][] = array(
            'name' => $name,
            'value' => $value,
            'type' => $type,
            'msg' => $msg,
            'helptext' => $helptext,
        );
    }

}

